package com.g04.by;

import java.util.LinkedList;
import java.util.Stack;

public class StackP {
}

class MinStack {
    private LinkedList<Integer> vals;
    private LinkedList<Integer> mins;

    public MinStack() {
        vals = new LinkedList<>();
        mins = new LinkedList<>();
    }

    public void push(int val) {
        vals.push(val);
        if (mins.isEmpty()) {
            mins.push(val);
        } else if (val < mins.peek()) {
            mins.push(val);
        } else {
            mins.push(mins.peek());
        }
    }

    public void pop() {
        vals.pop();
        mins.pop();
    }

    public int top() {
        return vals.peek();
    }

    public int getMin() {
        return mins.peek();
    }
}
